﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

using SBPweb.PROvibe.Business.Client.Library.Context;

namespace SBPweb.PROvibe.Modules.Client.Communication.Xmpp.Controls
{

    public partial class Login : ChildWindow
    {

        #region Constructor logic

        public Login()
        {
            InitializeComponent();
            RememberPassword = CookieHandler.Get<bool>("PROvibe_Messenger_XMPP_Remember");
            string userName = CookieHandler.Get<string>("PROvibe_Messenger_XMPP_UserName");
            string password = CookieHandler.Get<string>("PROvibe_Messenger_XMPP_Password");
            if (!string.IsNullOrEmpty(userName))
            {
                UserName = userName;
            }
            if (!string.IsNullOrEmpty(password))
            {
                Password = password;
            }
        }

        #endregion

        #region Property accessors

        public string UserName
        {
            get
            {
                return tbUserName.Text;
            }
            set
            {
                tbUserName.Text = value;
            }
        }

        public string Password
        {
            get
            {
                return pbPassword.Password;
            }
            set
            {
                pbPassword.Password = value;
            }
        }

        public bool? RememberPassword
        {
            get
            {
                return cbRemember.IsChecked;
            }
            set
            {
                cbRemember.IsChecked = value;
            }
        }

        #endregion

        #region Methods

        private void tbiLogin_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            CookieHandler.Put<bool>("PROvibe_Messenger_XMPP_Remember", RememberPassword.Value);
            CookieHandler.Put<string>("PROvibe_Messenger_XMPP_UserName", UserName);
            CookieHandler.Put<string>("PROvibe_Messenger_XMPP_Password", Password);
            DialogResult = true;
        }

        #endregion

    }

}